package com.example.restful01.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.restful01.mapper.BorrowRecordsMapper;
import com.example.restful01.model.BorrowRecords;
import com.example.restful01.service.BorrowRecordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BorrowRecordsServiceImpl extends ServiceImpl<BorrowRecordsMapper, BorrowRecords> implements BorrowRecordsService {
    @Autowired
    private BorrowRecordsMapper borrowRecordsMapper;
    @Override
    public boolean deleteBorrow(BorrowRecords borrowRecords) {
        return borrowRecordsMapper.deleteBorrow(
                borrowRecords.getReaderId(),
                borrowRecords.getBookId()
        ) > 0;
    }

    @Override
    public int addBorrow(BorrowRecords borrowRecords) {
        return borrowRecordsMapper.addBorrow(borrowRecords);
    }

    @Override
    public List<BorrowRecords> initBorrows(Integer readerId) {
        return borrowRecordsMapper.initBorrows(readerId);
    }

    @Override
    public Boolean returnBook(Integer recordId) {
        return borrowRecordsMapper.returnBook(recordId)>0;
    }

    @Override
    public boolean continueBorrow(Integer recordId) {
        return borrowRecordsMapper.continueBorrow(recordId)>0;
    }

    @Override
    public List<BorrowRecords> searchBorrow(String info) {
        return borrowRecordsMapper.searchBorrow(info);
    }
}
